from django.shortcuts import render,HttpResponse,redirect

# Create your views here.

def myform(request):
    return render(request,'myform.html')

def myform_single(request):
    if request.method=="GET":
        return render(request,'myform_single.html')
    if request.method=="POST":
        name=request.POST.get("name")
        password=request.POST.get("password")
        return HttpResponse("{},{}".format(name,password))

def aaa(request):
    if request.method=="GET":
        return render(request, 'aaa.html')
    if request.method=="POST":
        name = request.POST.get("name")
        age = request.POST.get("age")
        phone = request.POST.get("phone")
        if 'HTTP_FORWARDED_FOR' in request.META:
            user_ip = request.META['HTTP_FORWARDED_FOR']
        else:
            user_ip = request.META['REMOTE_ADDR']
        file=request.FILES.get("file")
        with open('{}.jpg'.format(name),'wb') as f:
            for chunk in file.chunks():
                f.write(chunk)
        return HttpResponse("姓名:{},年龄:{},手机号:{},ip:{},头像:{}".format(name,age,phone,user_ip,file))


def school(request):
    return redirect('aaa')

def school1(request):
    return render(request,'school1.html',{'list':['牛马','法外牛马']})










